#include "qlogmanager.h"

QLogManager::QLogManager(QObject *parent) :
    QObject(parent),
    m_max_log_count(MAX_LOG_COUNT)
{
}

void QLogManager::add_log(const QString &tag, const QString &text)
{
    tagLogInfo log;
    log.m_tag=tag;
    log.m_text=text;
    log.m_time=QDateTime::currentDateTime();
    m_logs.append(log);
    while(m_logs.size()>m_max_log_count)
    {
        m_logs.removeFirst();
    }
    emit refresh();
}

void QLogManager::clear()
{
    m_logs.clear();
    emit refresh();
}

QList<tagLogInfo> QLogManager::logs()
{
    return m_logs;
}

void QLogManager::set_max_count(int count)
{
    m_max_log_count=count;
    while(m_logs.size()>m_max_log_count)
    {
        m_logs.removeFirst();
    }
    emit refresh();
}
